﻿@using Smartstore.Web.Models.Catalog;

@model ProductReviewsModel

<script src="~/js/public.reviews.js" sm-target-zone="scripts"></script>

@if (Model.Items.Count == 0)
{
    <p class="text-muted">@T("Reviews.Empty")</p>
    return;
}

<div class="review-list fs-h6" id="review-list">
    @for (var i = 0; i < Model.Items.Count; i++)
    {
        var review = Model.Items[i];
        int ratingPercent = review.Rating * 20;
        var helpfulness = review.Helpfulness;

        <div class="review-item" id="review-item-@(i + 1)" itemscope
             attr-itemprop='(!Model.IsReviewsDetailPage, "review")'
             attr-itemtype='(!Model.IsReviewsDetailPage, "http://schema.org/Review")'>
            <div class="review-title">
                <div class="rating" itemprop="reviewRating" itemscope itemtype="https://schema.org/Rating">
                    <div style="width: @(ratingPercent)%"></div>
                    <meta itemprop="ratingValue" content="@review.Rating" />
                </div>
                <h4 itemprop="name">@review.Title</h4>
            </div>

            <div class="review-meta">
                <span sm-if="review.CustomerName.HasValue()" itemprop="author" itemscope itemtype="https://schema.org/Person">
                    <span class="review-meta-label">@T("Reviews.From"):</span>
                    @if (review.AllowViewingProfiles)
                    {
                        <a class="review-meta-value" asp-route="CustomerProfile" asp-route-id="@review.CustomerId" rel="nofollow" dir="auto" itemprop="name">
                            @(review.CustomerName)
                        </a>
                    }
                    else
                    {
                        <span class="review-meta-value" itemprop="name">@review.CustomerName</span>
                    }
                </span>

                <span class="review-meta-label d-flex align-self-start">@T("Common.Date"):</span>
                <span class="review-meta-value d-flex align-self-start text-nowrap" itemprop="datePublished" content="@review.WrittenOn.ToString("yyyy-MM-DD")">@review.WrittenOnStr</span>
            </div>

            <div sm-if="Model.ShowVerfiedPurchaseBadge" class="review-verify">
                <span class="small badge badge-@(review.IsVerifiedPurchase ? "success" : "secondary")">
                    @T("Reviews." + (review.IsVerifiedPurchase ? "Verified" : "Unverified"))
                </span>
            </div>

            <p class="review-text" dir="auto" itemprop="reviewBody">
                @Html.Raw(review.ReviewText)
            </p>

            <div class="review-vote d-flex" data-review-id="@(helpfulness.ProductReviewId)" data-href='@(Url.Action("SetReviewHelpfulness"))'>
                <span class="review-vote-label pr-2">@T("Reviews.Helpfulness.WasHelpful?")</span>
                <a class="review-vote-link review-vote-link-yes mr-1" href="#" title="@T("Common.Yes")" data-toggle="tooltip" rel="nofollow">
                    <i class="fa fa-thumbs-up"></i>
                    <span class="review-vote-count" data-bind-to="TotalYes">@(helpfulness.HelpfulYesTotal)</span>
                </a>
                <a class="review-vote-link review-vote-link-no mr-1" href="#" title="@T("Common.No")" data-toggle="tooltip" rel="nofollow">
                    <i class="fa fa-thumbs-down"></i>
                    <span class="review-vote-count" data-bind-to="TotalNo">@(helpfulness.HelpfulNoTotal)</span>
                </a>
            </div>

            <zone name="productreviews_page_inside_review" />
        </div>
    }
</div>

<div sm-if="Model.TotalReviewsCount > Model.Items.Count" class="text-center">
    <a class="btn btn-secondary" asp-action="Reviews" asp-route-id="@Model.ProductId" asp-fragment="review-item-11">
        <span>@T("Reviews.Overview.ReadAll")</span>
    </a>
</div>